package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.bean.Publisher;
import cn.jhc.dao.DaoType;
import cn.jhc.dao.PublisherDAO;
import cn.jhc.factory.DAOFactory;

/**
 * Servlet implementation class addPublisherservlet
 */
@WebServlet("/addpublisher.htm")
public class AddPublisherservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddPublisherservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String param = request.getParameter("publisherid");
		String name = request.getParameter("publishername");
		Publisher p = new Publisher();
		int id = Integer.parseInt(param);
		p.setId(id);
		p.setName(name);
		PublisherDAO pdao = (PublisherDAO)DAOFactory.getDao(DaoType.PUBLISHER);
		pdao.addPublisher(p);
		request.getRequestDispatcher("/admin/admin.jsp?body=/tiles/addpublisher.jsp").forward(request, response);
	}

	
}
